package handle

import (
    proto "github.com/golang/protobuf/proto"
    "rpcserver/message"
    "fmt"
)

func MessageTestHandleAdd(content []byte) (retctx []byte, retcode int32) {
    req:= &message.ReqAdd{}
    err := proto.Unmarshal(content, req)
    if err != nil {
        //TODO Log Error To Log File
        retcode = 10001
        return
    }
    result := req.GetParam1() + req.GetParam2()

    res := &message.ResAdd{}
    res.Result = proto.Int32(result)
    res.Retval = proto.Int32(0)

    retctx, err = proto.Marshal(res)
    if err != nil {
        //TODO Log Error To Log File
        retcode = 10002
    }

    return
}


func MessageTestHandleNotifyServer(content []byte) (retcode int32) {
    req:= &message.ReqNotifyServer{}
    err := proto.Unmarshal(content, req)
    if err != nil {
        //TODO Log Error To Log File
        retcode = 10001
        return
    }

    fmt.Printf("Notify Message = %s \n", req.GetMsg())
    fmt.Printf("Notify Value   = %d \n", req.GetVal())

    return
}
